#include "shader.h"
#include <cstring>
math::vec4f Shader::getVector(
	const std::map<uint32_t, BindingDescription>& bindingMap,
	const std::map<uint32_t, BufferObject*>& bufferMap,
	const uint32_t& attributeLocation,
	const uint32_t& index) {
    //1.找到vao中获取颜色，位置，uv等的  BindingDescription
	auto bindingIter = bindingMap.find(attributeLocation);
	if (bindingIter == bindingMap.end()) {
		assert(false);
	}

	auto bindingDescription = bindingIter->second;
    //2.找到对应的vboid
	auto vboID = bindingDescription.mVboId;
	auto vboIter = bufferMap.find(vboID);
	if (vboIter == bufferMap.end()) {
		assert(false);
	}
    //3.找到对应的vbo
	BufferObject* vbo = vboIter->second;
	//4.找到vbo中,对应ebo索引的数据，index从ebo数组中读出来
	uint32_t dataOffset = bindingDescription.mStride * index + bindingDescription.mOffset;
	uint32_t dataSize = bindingDescription.mItemSize * sizeof(float);
	const byte* buffer = vbo->getBuffer() + dataOffset;
	math::vec4f result;
	memcpy(&result, buffer, dataSize);
	return result;
}
